<template>
  <a-layout class="main">
    <a-layout-header class="main-header" v-if="!isOnlyContent">
      <topNav></topNav>
    </a-layout-header>
    <a-layout>
      <a-layout-sider class="side-menu" ref="mainSider" v-model="isCollapsed" v-if="!isOnlyContent">
        <side-menu :active-name="$route.name" :is-collapsed="isCollapsed" :menu-list="menuList"></side-menu>
      </a-layout-sider>
      <a-layout>
        <a-layout-header class="header-con" v-if="!isOnlyContent">
          <header-bar :is-collapsed="isCollapsed"></header-bar>
        </a-layout-header>
        <a-layout-content class="main-content">
          <div style="height:100%;">
            <router-view />
          </div>
        </a-layout-content>
      </a-layout>
    </a-layout>
  </a-layout>
</template>
<script>
import TopNav from './components/topNav'
import SideMenu from './components/side-menu'
import HeaderBar from './components/header-bar'

export default {
  components: {
    SideMenu,
    HeaderBar,
    TopNav
  },
  provide() {
    return { collapsedSider: this.collapsedSider }
  },
  data() {
    return {
      // 是否展开侧边栏
      isCollapsed: false
    }
  },
  computed: {
    // 导航菜单列表
    menuList() {
      return this.$store.state.routesConfig
    },
    // 是否只展示中心内容
    isOnlyContent() {
      return this.$store.state.user.isOnlyContent
    }
  },
  methods: {
    // 展开侧边栏
    collapsedSider() {
      this.isCollapsed = !this.isCollapsed
    }
  }
}
</script>

<style lang="less">
.main {
  height: 100%;

  .main-header {
    width: 100%;
    height: 56px;
    padding: 0;
  }

  .side-menu {
    user-select: none;
    overflow: hidden;
    min-width: 230px !important;
    max-width: 230px !important;
    width: 230px !important;
    background: #fff;
    box-shadow: 0 1px 4px rgb(0 21 41 / 8%);
    overflow: hidden;
  }

  .ant-layout-sider-collapsed {
    min-width: 88px !important;
    max-width: 88px !important;
    width: 88px !important;
    .ant-menu-inline-collapsed {
      width: 100%;
    }
  }

  .header-con {
    background: #fff;
    height: 50px;
    line-height: 50px;
    padding: 0;
  }

  .main-content {
    height: 100%;
    padding: 20px;
    overflow-y: auto;

    & > * {
      height: 100%;
    }
  }
}
</style>
